package res;

import com.alibaba.fastjson.JSON;
import com.codahale.metrics.annotation.Timed;
import orm.Method;
import orm.Result;
import util.HTTPTool;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 * Created by langdon on 2017/7/22.
 */

@Path("/api/v1/controller")
@Produces(MediaType.APPLICATION_JSON)
public class ControlRes {

    private static String name = "keyverify";

    private HTTPTool httpTool ;

    public ControlRes(){
        httpTool=new HTTPTool();
    }

    @POST
    @Timed
    public Result register(){
        //注册API
        Result result = httpTool.registerAPI();
        System.out.println(JSON.toJSON(result));
        return result;
    }

    @GET
    @Timed
    public Result request(){
        HTTPTool httpTool = new HTTPTool();
        Result result = httpTool.requestApi(name, "/application/api/v1/tokens?user=admin&password=456", Method.GET);
        return result;
    }

    @DELETE
    @Timed
    public Result revoke(){
        //撤销API
        Result result = httpTool.revokeAPI();
        System.out.println(JSON.toJSON(result));
        return result;
    }
}
